package com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.service.impl;

import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.entity.VillageTownHosPeoEntity;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.repository.VillageTownHostPeoRepository;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.economicLossDE.service.VillageTownHostPeoService;
import com.css.fxfzfxqh.util.PlatformObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VillageTownHostPeoServiceImpl implements VillageTownHostPeoService {
    @Autowired
    VillageTownHostPeoRepository villageTownHostPeoRepository;
    @Override
    public VillageTownHosPeoEntity findByProvinceAndCity(String provinceId, String cityId, String prefectureId, String townName) {

        if(PlatformObjectUtils.isEmpty(prefectureId)){

          return  villageTownHostPeoRepository.findByProvinceIdAndCityId(provinceId, cityId);
        }else{
            return villageTownHostPeoRepository.findByProvinceIdAndCityIdAndPrefectureId(provinceId,cityId,prefectureId);
        }
    }

    @Override
    public VillageTownHosPeoEntity findByProvinceAndCityForName(String provinceName,String cityName,String prefectureName,String townName) {

        if(PlatformObjectUtils.isEmpty(prefectureName)){

            return  villageTownHostPeoRepository.findByProvinceAndCity(provinceName, cityName);
        }else{
            return villageTownHostPeoRepository.findByProvinceAndCityAndPrefecture(provinceName,cityName,prefectureName);
        }
    }
}
